package huaweiod.first;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

/**
 * 华为OD机试真题 Java 实现【分奖金】【2022.11 Q4 新题】
 */
public class A_2023_45_ShareBonus {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List<Integer> collect = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int integer = in.nextInt();
            collect.add(integer);
        }
        Stack<Integer> stack = new Stack<>();
        int index = 0;
        int[] res = new int[n];
        while (index < n) {
            if (stack.isEmpty() || collect.get(stack.peek()) >= collect.get(index)) {
                stack.push(index++);
            } else {
                int preIndex = stack.pop();
                res[preIndex] = (index - preIndex) * (collect.get(index) - collect.get(preIndex));
            }
        }
        while (!stack.isEmpty()) {
            int cur = stack.pop();
            res[cur] = collect.get(cur);
        }
        String s = "";
        for (int i = 0; i < res.length; i++) {
            s += res[i] + " ";
            if (i == res.length - 1) {
                s = s.substring(0, s.length() - 1);
            }
        }
        System.out.println(s);
    }
}
